package com.gsmr.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gsmr.entity.PageBean;
import com.gsmr.entity.SysOperationRecord;
import com.gsmr.entity.User;
import com.gsmr.service.AlarmThresholdService;
import com.gsmr.service.FrontProcessorInfoService;
import com.gsmr.service.SysOperationRecordService;
import com.gsmr.util.PropertityUtil;
import com.gsmr.util.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author 作者 : 黄志新
 * @version 创建时间：2017年8月11日 上午12:13:57 类说明：用户Controller层
 */
@Controller
@RequestMapping("/sysOperationRecord")
public class SysOperationRecordController {

	@Resource
	private SysOperationRecordService sysOperationRecordService;

	@Resource
	private AlarmThresholdService alarmThresholdService;
	@Resource
	private FrontProcessorInfoService frontProcessorInfoService;

	/**
	 * 分页条件查询SysOperationRecord
	 */
	@RequestMapping("/list")
	public void list(
			@RequestParam(value = "page", required = false) String page,
			@RequestParam(value = "rows", required = false) String rows, 
			@RequestParam(value="startTime",required=false)String startTime,
			@RequestParam(value="endTime",required=false)String endTime,
			SysOperationRecord sysOperationRecord, HttpServletResponse response)
			throws Exception {
		PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
		Map<String, Object> map = new HashMap<>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
		if (startTime!=null&&!startTime.equals("NaN")){
			map.put("startTime", startTime);
		}
		if (endTime!=null&&!endTime.equals("NaN")){
			map.put("endTime", endTime);
		}
		List<SysOperationRecord> sysOperationRecordList = sysOperationRecordService.find(map);
		
		Long total = sysOperationRecordService.getTotal(map);
		JSONObject result = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(sysOperationRecordList);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);
	}

	/**
	 * 添加或者修改记录
	 * 
	 * @param user
	 * @param response
	 * @param flag
	 *            1 添加 2修改
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/save")
	public void save(
			@RequestParam(value = "frontProcessorId_") String frontProcessorId,
			@RequestParam(value = "reportInterva_") String reportInterva,
			@RequestParam(value = "reportInterval_old") String reportInterval_old,
			@RequestParam(value = "monitoringFrequency_") String monitoringFrequency,
			@RequestParam(value = "monitoringFrequency_old") String monitoringFrequency_old,
			@RequestParam(value = "ipAddress_") String ipAddress,
			@RequestParam(value = "ipAddress_old") String ipAddress_old,
			@RequestParam(value = "netMask_") String netMask,
			@RequestParam(value = "netMask_old") String netMask_old,
			@RequestParam(value = "gateWay_") String gateWay,
			@RequestParam(value = "gateWay_old") String gateWay_old,
			@RequestParam(value = "spectrumSendSwitch_") String spectrumSendSwitch,
			@RequestParam(value = "spectrumReportedIpAddress_") String spectrumReportedIpAddress,
			@RequestParam(value = "spectrumReportedIpAddress_old") String spectrumReportedIpAddress_old,
			@RequestParam(value = "signalSendSwitch_") String signalSendSwitch,
			@RequestParam(value = "signalReportedIpAddress_") String signalReportedIpAddress,
			@RequestParam(value = "signalReportedIpAddress_old") String signalReportedIpAddress_old,
			@RequestParam(value = "tchSendSwitch_") String tchSendSwitch,
			@RequestParam(value = "tchReportedIpAddress_") String tchReportedIpAddress,
			@RequestParam(value = "tchReportedIpAddress_old") String tchReportedIpAddress_old,
			@RequestParam(value = "gprsSendSwitch_") String gprsSendSwitch,
			@RequestParam(value = "gprsReportedIpAddress_") String gprsReportedIpAddress,
			@RequestParam(value = "gprsReportedIpAddress_old") String gprsReportedIpAddress_old,
			@RequestParam(value = "bottomNoiseThreshold") Integer bottomNoiseThreshold, 
			@RequestParam(value = "bottomNoiseThreshold_old") Integer bottomNoiseThreshold_old,
			SysOperationRecord sysOperationRecord, HttpServletResponse response, Integer flag) throws Exception {
		
		
		int resultTotal = 0; // 操作的记录条数
		if (flag == 1) {
			ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
			LinkedHashMap<String,Object> hm = new LinkedHashMap<>();
			hm.put("operateTime", System.currentTimeMillis());
			hm.put("userId", sysOperationRecord.getUserId());
			hm.put("operationType", sysOperationRecord.getOperationType());
			hm.put("oldValue", sysOperationRecord.getOldValue());
			hm.put("newValue", sysOperationRecord.getNewValue());
			hm.put("isImplemented", sysOperationRecord.getIsImplemented());
			hm.put("isSuccessful", sysOperationRecord.getIsSuccessful());
			sysoperationrecordList.add(hm);
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
			map.put("list", sysoperationrecordList);
			resultTotal = sysOperationRecordService.add(map);
		} else if (flag == 2) {
			User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
			ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
			/*if (!ipAddress.equals(ipAddress_old)) {
				LinkedHashMap hm = new LinkedHashMap();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("oldValue", null);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				hm.put("operationType", 6);
				jsonObject.put("ipAddress", ipAddress);
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
			}*/
			if ((!ipAddress.equals(ipAddress_old))|| (!netMask.equals(netMask_old)) || (!gateWay.equals(gateWay_old))) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("oldValue", null);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				hm.put("operationType", 6);
				jsonObject.put("ipAddress", ipAddress);
				jsonObject.put("netMask", netMask);
				jsonObject.put("gateWay", gateWay);
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
			}
			/*if (!gateWay.equals(gateWay_old)) {
				LinkedHashMap hm = new LinkedHashMap();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("oldValue", null);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				hm.put("operationType", 6);
				jsonObject.put("ipAddress", ipAddress);
				jsonObject.put("netMask", netMask);
				jsonObject.put("gateWay", gateWay);
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
			}*/
			if(!reportInterva.equals(reportInterval_old)){
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("oldValue", null);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				hm.put("operationType", 4);
				jsonObject.put("reportInterval", Integer.parseInt(reportInterva));
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
			}
			if (!monitoringFrequency.equals(monitoringFrequency_old)) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("oldValue", null);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				hm.put("operationType", 5);
				jsonObject.put("monitoringFrequency", Integer.parseInt(monitoringFrequency));
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
				
			}
			if (!spectrumReportedIpAddress.equals(spectrumReportedIpAddress_old)) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				jsonObject.put("spectrumSendSwitch", Integer.parseInt(spectrumSendSwitch));
				jsonObject.put("reportedIpAddress", spectrumReportedIpAddress);
				hm.put("operationType", 3);
				hm.put("newValue", jsonObject.toString());
				
				jsonObject.put("reportedIpAddress", spectrumReportedIpAddress_old);
				hm.put("oldValue", jsonObject.toString());
				
				sysoperationrecordList.add(hm);
			}
			if (!signalReportedIpAddress.equals(signalReportedIpAddress_old)) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				jsonObject.put("signalSendSwitch", Integer.parseInt(signalSendSwitch));
				jsonObject.put("reportedIpAddress", signalReportedIpAddress);
				hm.put("operationType", 2);
				hm.put("newValue", jsonObject.toString());
				
				jsonObject.put("reportedIpAddress", signalReportedIpAddress_old);
				hm.put("oldValue", jsonObject.toString());
				
				sysoperationrecordList.add(hm);
			}
			if (!tchReportedIpAddress.equals(tchReportedIpAddress_old)) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				jsonObject.put("tchSendSwitch", Integer.parseInt(tchSendSwitch));
				jsonObject.put("reportedIpAddress", tchReportedIpAddress);
				hm.put("operationType", 1);
				hm.put("newValue", jsonObject.toString());
				
				jsonObject.put("reportedIpAddress", tchReportedIpAddress_old);
				hm.put("oldValue", jsonObject.toString());
				
				sysoperationrecordList.add(hm);
			}
			if (!gprsReportedIpAddress.equals(gprsReportedIpAddress_old)) {
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("isImplemented", 0);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				jsonObject.put("gprsSendSwitch", Integer.parseInt(gprsSendSwitch));
				jsonObject.put("reportedIpAddress", gprsReportedIpAddress);
				hm.put("operationType", 11);
				hm.put("newValue", jsonObject.toString());
				
				jsonObject.put("reportedIpAddress", gprsReportedIpAddress_old);
				hm.put("oldValue", jsonObject.toString());
				
				sysoperationrecordList.add(hm);
			}

			if (!bottomNoiseThreshold_old.equals(bottomNoiseThreshold)) {
				Map<String, Object> map = new HashMap<>();
				map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
				map.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				map.put("bottomNoiseThreshold", bottomNoiseThreshold);
				resultTotal = frontProcessorInfoService.update(map);
				LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
				hm.put("operateTime", System.currentTimeMillis());
				hm.put("userId", 1);
				hm.put("isImplemented", 1);
				hm.put("isSuccessful", 1);
				hm.put("operationType", 12);
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
				jsonObject.put("bottomNoiseThreshold", bottomNoiseThreshold_old);
				
				hm.put("oldValue", jsonObject.toString());
				jsonObject.put("bottomNoiseThreshold", bottomNoiseThreshold);
				hm.put("newValue", jsonObject.toString());
				sysoperationrecordList.add(hm);
			}

			//System.out.println("bottomNoiseThreshold: " + bottomNoiseThreshold);

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
			map.put("list", sysoperationrecordList);
			if(sysoperationrecordList.size()>0){
				resultTotal = sysOperationRecordService.add(map);
			}
		}
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
	}

	/**
	 * 发送频谱数据
	 */
	@RequestMapping("/sendSpectrum")
	public String sendSpectrum(
			@RequestParam(value = "id") String id,
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			@RequestParam(value = "spectrumSendSwitch") String spectrumSendSwitch,
			@RequestParam(value = "spectrumReportedIpAddress") String spectrumReportedIpAddress,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 3);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		jsonObject.put("spectrumSendSwitch", Integer.parseInt(spectrumSendSwitch));
		jsonObject.put("reportedIpAddress", spectrumReportedIpAddress);
		hm.put("newValue", jsonObject.toString());
		jsonObject.put("spectrumSendSwitch", spectrumSendSwitch.equals("1")?2:1);
		hm.put("oldValue", jsonObject.toString());
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 发送信令数据
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/sendSignal")
	public String sendSignal(
			@RequestParam(value = "id") String id,
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			@RequestParam(value = "signalSendSwitch") String signalSendSwitch,
			@RequestParam(value = "signalReportedIpAddress") String signalReportedIpAddress,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 2);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		jsonObject.put("signalSendSwitch", Integer.parseInt(signalSendSwitch));
		jsonObject.put("reportedIpAddress", signalReportedIpAddress);
		hm.put("newValue", jsonObject.toString());
		jsonObject.put("signalSendSwitch", signalSendSwitch.equals("1")?2:1);
		hm.put("oldValue", jsonObject.toString());
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 发送TCH业务
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/sendTch")
	public String sendTch(
			@RequestParam(value = "id") String id,
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			@RequestParam(value = "tchSendSwitch") String tchSendSwitch,
			@RequestParam(value = "tchReportedIpAddress") String tchReportedIpAddress,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 1);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		jsonObject.put("tchSendSwitch", Integer.parseInt(tchSendSwitch));
		jsonObject.put("reportedIpAddress", tchReportedIpAddress);
		hm.put("newValue", jsonObject.toString());
		jsonObject.put("tchSendSwitch", tchSendSwitch.equals("1")?2:1);
		hm.put("oldValue", jsonObject.toString());
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 获取前置机最新状态的数据
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/reloadFrontEndProcessorConfiguration")
	public String reloadFrontEndProcessorConfiguration(
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 7);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		hm.put("newValue", jsonObject.toString());
		hm.put("oldValue", null);
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 获取前置机重启事件时刻表的数据
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getFrontEndProcessorRestartEventTimetable")
	public String getFrontEndProcessorRestartEventTimetable(
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 8);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		hm.put("newValue", jsonObject.toString());
		hm.put("oldValue", null);
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 清除故障记录和重启事件记录的数据
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/clearFaultRecordAndRestartEventRecord")
	public String clearFaultRecordAndRestartEventRecord(
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 9);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		hm.put("newValue", jsonObject.toString());
		hm.put("oldValue", null);
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 发送GPRS数据
	 * 
	 * @param sysOperationRecord
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/sendGprs")
	public String sendGprs(
			@RequestParam(value = "id") String id,
			@RequestParam(value = "frontProcessorId") String frontProcessorId,
			@RequestParam(value = "gprsSendSwitch") String gprsSendSwitch,
			@RequestParam(value = "gprsReportedIpAddress") String gprsReportedIpAddress,
			SysOperationRecord sysOperationRecord, HttpServletResponse response) throws Exception {
		int resultTotal=0;
		User user = (User) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		ArrayList<Map<String, Object>> sysoperationrecordList = new ArrayList<>();
		LinkedHashMap<String, Object> hm = new LinkedHashMap<>();
		hm.put("operateTime", System.currentTimeMillis());
		hm.put("userId", 1);
		hm.put("operationType", 11);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("frontProcessorId", Integer.parseInt(frontProcessorId));
		jsonObject.put("gprsSendSwitch", Integer.parseInt(gprsSendSwitch));
		jsonObject.put("reportedIpAddress", gprsReportedIpAddress);
		hm.put("newValue", jsonObject.toString());
		jsonObject.put("gprsSendSwitch", gprsSendSwitch.equals("1")?2:1);
		hm.put("oldValue", jsonObject.toString());
		hm.put("isImplemented", 0);
		sysoperationrecordList.add(hm);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("database_name", PropertityUtil.NETWORK_MANAGEMENT_DATABASE_NAME);
		map.put("list", sysoperationrecordList);
		resultTotal = sysOperationRecordService.add(map);
		JSONObject result = new JSONObject();
		if (resultTotal > 0) {
			result.put("success", true);
		} else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}
	
}
